package org.fao.pims.web.manage.book;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.ajaxtags.servlets.BaseAjaxServlet;
import org.ajaxtags.xml.AjaxXmlBuilder;
import org.fao.pims.persistence.TaxonDAO;
import org.fao.pims.persistence.TaxonDAOImpl;

public class BookAutocompleteServlet extends BaseAjaxServlet {

	public String getXmlContent(HttpServletRequest request, HttpServletResponse response)
	throws Exception {

	String subString = request.getParameter("name");
	
	System.out.println("substring: " + subString);
	
	TaxonDAO dao = new TaxonDAOImpl();
	
	List nameList = dao.getTaxonByName(subString);
	
	
	
	String xml = new AjaxXmlBuilder().addItems(nameList, "commonAndScientName", "scientificName", true).toString(); 
	
	System.out.println(xml);
	
	return xml;
}

}
